package com.example.administrator.recycler_test;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class PhotoAdapter extends RecyclerView.Adapter <PhotoAdapter.ViewHolder>{

    private List<Photo> mPhotoList;

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView image;
        TextView name;

        public  ViewHolder(View view) {
            super(view);
            image = (ImageView) view.findViewById(R.id.photo_image_test);
            name = (TextView) view.findViewById(R.id.photo_name_test);
        }
    }

    public PhotoAdapter(List<Photo> PhotoList) {
        mPhotoList = PhotoList;
    }

    //导入布局
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.photo_item, viewGroup, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    //获取数据
    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        Photo photo = mPhotoList.get(i);
        viewHolder.image.setImageResource(photo.getImage());
        viewHolder.name.setText(photo.getName());
        Log.d("TAG", "debugi " + i);
    }

    //内容大小
    @Override
    public int getItemCount() {
        return mPhotoList.size();
    }
}
